<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>


<link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/bootstrap/css/bootstrap.min.css">

<link href="__PUBLIC__/Admin/css/style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/js/artDialog/skins/blue.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/validform/style.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/ThinkBox/css/ThinkBox.css" media="all">

<script src="__PUBLIC__/Admin/bootstrap/js/jquery.min.js"></script>
<script src="__PUBLIC__/Admin/bootstrap/js/bootstrap.min.js"></script>
<script src="__PUBLIC__/Admin/js/artDialog/artDialog.js"></script>
<script src="__PUBLIC__/Admin/js/artDialog/plugins/iframeTools.js"></script>
<script src="__PUBLIC__/Admin/js/My97DatePicker/WdatePicker.js"></script>
<script src="__PUBLIC__/Js/validform/Validform.js"></script>
<script src="__PUBLIC__/Js/ThinkBox/jquery.ThinkBox.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<script>


//显示图片选择框
var mydialog = art.dialog;
function showImgBox(curElement){
	art.dialog.data('curElement',curElement);
	art.dialog.open('{:U('Img/imagesBox')}', {width: 800, height: 500,lock:true,title:'选择图片', ok:function(){
			var d = this.iframe.contentWindow.document;
			var img_url = $(d).find('#Imgselected').attr('img_url');
			$(curElement).parent().find("input[type='hidden']").eq(0).val(img_url);
			$(curElement).val('__PUBLIC__'+img_url);
			$(curElement).focus();
			$(curElement).blur();
			curElement.src = '__PUBLIC__'+img_url;
	}});
}

//风格选择	 
function showPagesBox(curElement){
	art.dialog.data('curElement',curElement);
	art.dialog.open('{:U('Pages/pagesBox')}', {width: 800, height: 500,lock:true,title:'选择显示风格', ok:function(){
			var d = this.iframe.contentWindow.document;
			var img_url = $(d).find('#Imgselected').attr('img_url');
			$(curElement).parent().find("input[type='hidden']").eq(0).val(img_url);
			$(curElement).val('__PUBLIC__'+img_url);
			$(curElement).focus();
			$(curElement).blur();
			curElement.src = '__PUBLIC__'+img_url;
	}});
}


    function error(msg){
		var d = artDialog({
			title: '操作错误',
			content: msg,
			cancel: false,
			ok: function () {
				
				}
		});
		d.show();
	}
	function success(msg){
		var d = artDialog({
			title: '操作成功',
			content: msg,
			cancel: false,
			ok: function () {
				
				}
		});
		d.show();
	}
	
	function sall(){
		
		$('.sall').each(function(index, element) {
            if($(this).prop('checked')== true){
				$(this).prop('checked',false);
				$(this).parent('.checked').removeClass('checked');
			}else{

				$(this).prop('checked',true);
				$(this).parent().addClass('checked');
			}
        });
  
	}
	
	function rall(){
		$('.sall').prop('checked',false);
		$('.sall').parent().removeClass('checked')
	}
	
	
	//移动内容 到分类
	function movenews(e){
		var ids=new Array();
		$('.sall').each(function(index, element) {
            if($(this).attr('checked')=='checked'){
				ids.push($(this).val());
			}
        });
		if(ids.length>0){
			if(confirm('您确定要移动选中记录吗？')){
			    window.location.href="{:U('move')}?id="+ids.toString()+"&category_id="+e.value;
			}else{
				return false;
			}
		}else{
			error('请选择要移动的记录');
		}
	}
	function delall(){
		var ids=new Array();
		$('.sall').each(function(index, element) {
            if($(this).prop('checked')== true){
				ids.push($(this).val());
			}
        });
		if(ids.length>0){
			if(confirm('您确定要删除选中记录吗？')){
			    window.location.href="{:U('delete')}?id="+ids.toString();
			}else{
				return false;
			}
		}else{
			error('请选择要删除的记录');
		}
	}
	
	
	function ajaxText(e){
		var tablename = $(e).parent().attr('tablename');
		var field = $(e).parent().attr('field');
		var id = $(e).parent().attr('id');
		var val = $(e).val();
		$.post('{:U('ajaxText')}',{tablename:tablename,field:field,id:id,val:val},function(data){
			if(data.status == 1){
			    $(e).parent().text(data.data);
			}else{
				alert(data.info);
			}
		},'json');
	}
	
	$(document).ready(function(e) {
		//点击ajax修改文字
		$('span.ajaxText').each(function(index, element) {
			$(this).click(function(e) {
				if($(this).find('input').length == 0){
			    var text = $(this).text();
                var input = $('<input type="text" onBlur="ajaxText(this);" style="width:100%; max-width:100%;" class="form-control" value="">');
				$(this).empty();
				input.appendTo($(this));
				input.focus().val(text);
				}
            });
            
        });
		
		//清除缓存
		$('#clearCache').click(function(e) {
            $.post('{:U('clearCache')}',{},function(data){
				if(data.status == 1){
					$.ThinkBox.success(data.info,{'delayClose':100});
				}else{
					$.ThinkBox.error(data.info,{'delayClose':200});
				}
			},'json');
        });
		
		//表单验证
		$(".checkoutform:eq(0)").Validform({
			ajaxPost:true,
			tiptype:function(data,s){
				if(s.type == 1){
					$.ThinkBox.success(data,{'delayClose':100});
				}
			},
			callback:function(data){
				//检测登录 
				
				if(data.status == 0){
					$.ThinkBox.error(data.info,{'delayClose':200});
					
				}else{
					
					$.ThinkBox.success(data.info,{'delayClose':200}); 
					    
							try{
							    window.parent.submitSuccess(data.status,data.info,data.data);
								mydialog.close();
							}catch (e){
								window.parent.location.href=data.url;
							}
						
				}
			}
	    });
 		//头部菜单 
		$('.topmenu').each(function(index, element) {
            $(this).mouseenter(function(e) {
				$(this).addClass('cur');
                $(this).find('ul').removeClass('h');
            });
			$(this).mouseleave(function(e) {
				$(this).removeClass('cur');
                $(this).find('ul').addClass('h');
            });
        });
		
		
        /*$('.data_list').each(function(index, element) {
            $(this).mouseenter(function(e) {
                $(this).css({'background':'#D7F7F9'});
            });
			$(this).mouseleave(function(e) {
                $(this).css({'background':'#fff'});
            });*/
			//$(this).find("input[type='checkbox']").click();
			/*$(this).find("input[type='checkbox']").click(function(){
					if($(this).attr('checked')=='checked'){
					
					    $(this).attr('checked',false);
				    }else{
					    $(this).attr('checked',true);
				    }
				});
			$(this).find("input[type='checkbox']").parent().click(function(e) {
				
                if($(this).find("input[type='checkbox']").attr('checked')=='checked'){
					
					$(this).find("input[type='checkbox']").attr('checked',false);
				}else{
					$(this).find("input[type='checkbox']").attr('checked',true);
				}
            });
        });*/

		
		//异步更新int字段
		$('.status_btn').each(function(index, element) {
            $(this).click(function(e) {
				$.ajax({
					url:"<?php echo U('ajaxUpdate');?>",
					type:"post",
					data:"data="+$(this).attr('field'),
					dataType:"json",
					success: function(data){
						if(data.status==1){
							$('.status_btn').eq(index).removeClass("status1");
							$('.status_btn').eq(index).removeClass("status0");
							$('.status_btn').eq(index).addClass("status"+data.data);
						}
					}
				});
            });
        });
    });
	
	//更新排序
	//key主键/field更新字段名/el当前按钮对象/url服务端地址
	function update_sort(key,field,el,url){
		var data=new Array();
		$("input[name='"+key+"']").each(function(index, element) {
            data.push($(this).val()+'_'+$(this).parent().parent().find("input[name='"+field+"']").val());
        });
		$.post(url,{'sort':data.toString(),'field':field},function(data){
			if(data=='OK'){
				if(el==''){
					success('更新成功');
				}
			}else{
				error('更新失败');
			}
		});
	}
	
	//更新排序,点击移动更新
	function update_sortClick(key,type,el,field,sendurl){
		var data=new Array();
		if(type=='up'){
			$(el).parent().parent().after($(el).parent().parent().prev());
		}else{
			$(el).parent().parent().next().after($(el).parent().parent());
		}
		$("input[name='"+key+"']").each(function(index, element) {
			$(this).parent().parent().find("input[name='"+field+"']").val(index+1);
            data.push($(this).val()+'_'+$(this).parent().parent().find("input[name='"+field+"']").val());
        });
		
		//列新排序
		update_sort(key,field,el,sendurl);
	}
	
	
	
</script> 
<body>




<!--头部结束--> 

<div class="container main"> <include file="Public:left" />
  <div class="w790">
    <div class="table_">
      <table width="98%" cellpadding=0 cellspacing=0 class="table table-bordered">
        <tr class="row" >
          <th height="20" align="center" >文件名
            </td >
          <th align = "center" > 备份时间
            </td>
          <th align="center" >文件大小
            </td >
          <th align = "center" > 管理选项
            </td>
        </tr >
        <?php
       

        $FileArr = MyScandir($DataDir);
        foreach($FileArr as $i =>$n) {
            if ($i > 1) {
                $files = MyScandir($DataDir.DIRECTORY_SEPARATOR.$n);
                foreach($files as $k => $v){
                    $FileSize += filesize($DataDir.DIRECTORY_SEPARATOR.$n.DIRECTORY_SEPARATOR.$v);
                }
                $FileTime = date('Y-m-d H:i:s', filemtime($DataDir.'/'.$n));
                

                if ($FileSize < 1024*1024) {
                    $FileSize = number_format($FileSize/1024, 2).'KB';
                } else {
                    $FileSize = '<font color="#FF0000">'.number_format($FileSize/1024/1024, 2).'</font>MB';
                }
                $sAS = "<a href=\"?Action=dow&file=".$n."\">下载</a> | ";
                $sAS.= "<a onClick=\"return confirm('确定将数据库还原到当前备份吗？');\" href=\"?Action=RL&File=$n\">还原</a> | ";
                $sAS.= "<a onClick=\"return confirm('确定删除该备份文件吗？');\" href=\"?Action=Del&File=$n\">删除</a>";
                echo "<tr class=\"row\">
                <td height=\"20\" align=\"center\">$n</td>
                <td align=\"center\">$FileTime</td>
                <td align=\"center\">$FileSize</td>
                <td align=\"center\">$sAS</td>
                </tr>";
                unset($FileTime, $FileSize, $sAS); 
            } 
        } ?>
        <tr class="row">
          <td colspan="4" height="40" align="center"><input type="button" value="备份数据" style="width:120px; height:28px;cursor: hand" onClick="javascript:location.href='{:U('index', array('Action' => 'backup', 'backuptype' => 'data'))}'">
            <input type="button" value="备份结构" style="width:120px; height:28px;cursor: hand" onClick="javascript:location.href='{:U('index', array('Action' => 'backup', 'backuptype' => 'structure'))}'">
            <input type="button" value="备份整个数据库" style="width:120px; height:28px;cursor: hand" onClick="javascript:location.href='{:U('index', array('Action' => 'backup', 'backuptype' => 'all'))}'">
            
            
            <!--<input type="button" value="导出安装数据包" style="width:120px; height:28px;cursor: hand" onClick="javascript:location.href='{:U('index', array('Action' => 'backupstructure', 'backuptype' => 'all'))}'">-->
            
            <input type="button" value="导出安装数据包" style="width:120px; height:28px;cursor: hand" data-toggle="modal" data-target="#myModalsetup"> 
            <input type="button" value="打包当前站点数据" style="width:120px; height:28px;cursor: hand" data-toggle="modal" data-target="#myModal">
            
            
            <a href="{:U('backnewsimgage')}" target="_blank">打包当前站点图片</a>
            
            </td>
        </tr>
      </table>
    </div>
  </div>
  <div class="clear"></div>
</div>
<form action="{:U('backupSite')}" method="get"> 
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="myModalLabel">请输入您要转移的数据目标站点ID</h4>
        </div>
        <div class="modal-body">
          <label for="exampleInputName2">请输入ID号</label>
          <br>
          <input type="hidden" value="" id="order_id" name="order_id">
          <input type="text" class="form-control" id="" value="0" name="tositeid" placeholder="目标站点ID">
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
          <button type="submit" class="btn btn-primary">确认</button>
        </div>
      </div>
    </div>
  </div>
</form>


<form action="{:U('index')}" method="get"> 
  <div class="modal fade" id="myModalsetup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="myModalLabel">选择一个角色</h4>
        </div>
        <div class="modal-body">

          <input type="hidden" name="Action" value="backupstructure">
          <input type="hidden" name="backuptype" value="all">
         <div>
            <select class="form-control" name="role[]" size="15" multiple="multiple">
                <volist name="role_list" id="vo">
                    
                    <option value="{$vo.id}">{$vo.name}</option>
                    
                </volist>
            </select>
        </div><br>

        
        <label><input type="radio" checked name="copyfile" value="1" /> 生成完整的安装包</label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<label><input type="radio" name="copyfile" value="2" /> 只生成升级文件</label>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
          <button type="submit" class="btn btn-primary">确认</button>
        </div>
      </div>
    </div>
  </div>
</form>


<div style="height:80px;"></div>
</body></html>